/**
 * 	 Copyright (c) 2008, 2009 Lukas Zaruba
 * 
 *   This file is part of UniAnalyzer (Universal Analyzer).
 *
 *   UniAnalyzer is free software: you can redistribute it and/or modify
 *   it under the terms of the GNU Lesser General Public License as published by
 *   the Free Software Foundation, either version 3 of the License, or
 *   (at your option) any later version.
 *
 *   UniAnalyzer is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *   GNU Lesser General Public License for more details.
 *
 *   You should have received a copy of the GNU Lesser General Public License
 *   along with UniAnalyzer. If not, see <http://www.gnu.org/licenses/>.
 */

package net.zarubsys.unianalyzer.dataviews.lpt.table.dataProvider;

import java.text.DecimalFormat;

import net.zarubsys.unianalyzer.dataminers.lpt.results.IResult;

/**
 * TableDataProvider
 *
 * @author  &lt;A HREF=&quot;mailto:lukas.zaruba@media-solutions.cz&quot;&gt;Lukas Zaruba&lt;/A&gt;, MEDIA SOLUTIONS CZECH REPUBLIC Ltd.
 * @version $Revision$ $Date$
 */
public class TableDataProvider {
	public static final int DECIMAL = 1;
	public static final int HEX = 2;
	public static final int BINARY = 3;
	
	public static final int SECOND = 1;
	public static final int MILISECOND = 1000;
	public static final int MICROSECOND = 1000000;
	
	private final IResult result;
	private final int style;
	private final int time;
	
	public TableDataProvider(IResult result, int style, int time) {
		this.result = result;
		this.style = style;
		this.time = time;
	}
	
	public String[] getRowData(int rowNumber) {
		float timeValue = rowNumber / result.getRealFrequency(); 
		String rowNumberString = String.valueOf(rowNumber);
		DecimalFormat df;
		switch (time) {
		case 1:
			df = new DecimalFormat("0.000000");
			break;
		case 1000:
			df = new DecimalFormat("0.000");
			timeValue *= 1000;
			break;
		case 1000000:
			df = new DecimalFormat("0.0");
			timeValue *= 1000 * 1000;
			break;
		default:
			throw new IllegalArgumentException("Illegal time value: Time value has to be 1, 1000, or 1000000!!!");
		}
		String time = df.format(timeValue);
		String valueString;
		int contentAtRow = result.getContentAtPosition(rowNumber);
		switch (style) {
		case DECIMAL:
			valueString = String.valueOf(contentAtRow);
			break;
		case HEX:
			valueString = Integer.toHexString(contentAtRow) + "h";
			break;
		case BINARY:
			valueString = Integer.toBinaryString(contentAtRow) + "b";
			break;
		default:
			throw new IllegalArgumentException("Illegal row number: It must be DECIMAL, HEX or BINARY");
			
		}
		
		return new String[] {rowNumberString, time, valueString};
		
	}

}


/*
 * $Log$
 */